package t.l.component;

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JComponent;

public class Person extends JComponent {
  public static final Color NORMAL_COLOR = Color.LIGHT_GRAY;
  public static final Color CHOSE_COLOR = Color.GREEN;
  private int diameter = 30;
  private int num;
  private Color color = NORMAL_COLOR;

  public void setColor(Color color) {
    this.color = color;
  }

  public Color getColor() {
    return color;
  }

  public void refreshBound(int x, int y) {
    setBounds(x, y, diameter, diameter);
  }

  public int getDiameter() {
    return diameter;
  }

  public Person(int num) {
    this.num = num;
  }

  public int getNum() {
    return num;
  }

  @Override public void paint(Graphics g) {
    if (g == null) {
      System.out.println("graphics is empty, person : " + num);
      return;
    }
    Color originColor = g.getColor();
    g.setColor(new Color(0, 0, 0, 0));
    g.setColor(color);
    g.fillOval(0, 0, diameter, diameter);
    g.setColor(Color.WHITE);
    String sValue = String.valueOf(num);
    g.drawString(sValue, diameter / 2 - g.getFontMetrics().stringWidth(sValue) / 2,
        diameter / 2 + g.getFontMetrics().getHeight() / 3);
    g.setColor(originColor);
  }
}
